<template>
	<view>
		<view class="container">
			<!-- 标题输入 -->
			<input type="text" v-model="postTitle" placeholder="请输入帖子标题" />
			<!-- 内容输入 -->
			<textarea v-model="postContent" placeholder="请输入帖子内容"></textarea>
		</view>
		<!-- 发布按钮 -->
		<button @click="publishPost">发布帖子</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				postTitle: '',
				postContent: ''
			};
		},
		methods: {
			publishPost() {
			    this.$request({
			        url: '/posts?title=' + this.postTitle + '&content=' + this.postContent,
			        method: 'POST',
			    }).then(res => {
			        console.log('Post response:', res);
			        uni.showToast({
			            title: '发布成功',
			            icon: 'none'
			        });
			    }).catch(err => {
			        console.error('Post request failed', err); // 添加日志输出
			        // 处理请求失败的情况
			        uni.showToast({
			            title: '发布失败，请稍后重试',
			            icon: 'none'
			        });
			    });
			}
		}
	};
</script>
<style>
	* {
		margin: 3px;
	}

	.container {
		padding-top: 20px;
	}

	textarea {
		width: 100%;
		border: 1px solid #F0F0F0;
		/* 为多行文本输入框添加边框线 */
		border-radius: 5px;
	}
</style>